/*************************************************************************
	> File Name: vfork.c
	> Author: Angel Criss
	> Blog: blog.abbycin.tk 
	> Created Time: Sun 06 Jul 2014 02:42:56 PM CST
 ************************************************************************/

#include"head.h"

//static int out=10;
main()
{
    pid_t child;

    int in=10;
/*
 *  better not use vfork; because it's fast but a little bit weird
 */
    switch(child=vfork()){
        case -1:
            err("vfork");
        case 0:
  //          out*=3;
            in*=3;
            //for(;;); //zombie
    printf("PID: %ld %s; in: %d\n",(long)getpid(),(child==0)?"(child)":"(parent)",in);
            //break;  // cant use break
            _exit(0);
        default:
            sleep(3);
    printf("PID: %ld %s; in: %d\n",(long)getpid(),(child==0)?"(child)":"(parent)",in);
            //break;  // cant use break
            _exit(0);
    }
    //printf("PID: %ld %s; in: %d\n",(long)getpid(),(child==0)?"(child)":"(parent)",in);
}
